<template>
  <div>
    <FormPanel ref="formPanel" :list="formList" :cols="1" :labelWidth="110" formType="add" :isSubmitBtn="false" />
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'center'
      }"
    >
      <el-button type="primary" @click="openPrint">打 印</el-button>
      <el-button @click="closeDialog">取 消</el-button>
    </div>
    <div v-if="isOrderShow">
      <BasePrint ref="print" :data="printList" template="templatePrintFee" />
    </div>
  </div>
</template>

<script>
import moment from 'moment';
import QRcode from 'qrcode';
import { dictionary } from '@/utils/dictMixin';
import { searchRoleByCode } from '@/api/common/empSelect/index';
import { findAllRepair } from '@/api/repair/basicParameters';
import { firstPrintRepairOrder, getRepairOrderPrintInfo } from '@/api/repair/repairReception/customer';
import { queryPrintData } from '@/api/repair/repairReception/feesSettlement';

import dictCode from '@/utils/dictCode';
export default {
  name: 'printOrder',
  mixins: [dictionary],
  props: ['roNo', 'printTitle'],
  data() {
    this.dmsFunc = { dmsFuncId: 55100010 };
    return {
      formList: this.createFormList(),
      printList: {},
      isOrderShow: false
    };
  },
  created() {
    // this.formList.forEach(x => {
    //   x.initialValue = this.rowData[x.fieldName];
    // });
  },
  mounted() {
    this.getObject();
    this.getPrintData();
  },

  methods: {
    createFormList() {
      return [
        {
          type: 'SELECT',
          label: '收费对象',
          fieldName: 'object',
          placeholder: '请选择',
          initialValue: '',
          // disabled: true,
          change: val => {
            // this.changeBrand(val);
            // this.$refs.baseInfoFormPanel.SUBMIT_FORM();
          },
          itemList: [],
          rules: [{ required: false, message: '请选择收费对象', trigger: 'change' }]
        }
      ];
    },

    // 获取收费对象
    getObject() {
      let arr = [];
      arr.push({ text: '全部', value: 'all' });
      this.formList.find(item => item.fieldName === 'object').itemList = arr;
    },

    async getPrintData() {
      let res = await getRepairOrderPrintInfo(this.roNo); // 获取打印主数据
      let res1 = await queryPrintData(this.roNo, 1); // 获取打印表头数据
      console.log(res, 'res----');
      console.log(res1, 'res1');
      if (res.resultCode == 200 && res1.resultCode == 200) {
        this.printList = _.cloneDeep(res.data);
        if (res1.data.companyInfo) {
          this.printList['companyNameCn'] = res1.data.companyInfo.companyNameCn;
          this.printList['companyNameEn'] = res1.data.companyInfo.companyNameEn;
          this.printList['addressZh'] = res1.data.companyInfo.addressZh;
          this.printList['addressEn'] = res1.data.companyInfo.addressEn;
          this.printList['phone'] = res1.data.companyInfo.phone;
          this.printList['zipCode'] = res1.data.companyInfo.zipCode;
          this.printList['fax'] = res1.data.companyInfo.fax;
        }
        console.log(this.printList, 'printList', res.data);
      }
    },

    openPrint() {
      // 点击打印工单
      // let roNo = {
      //   roNo: this.roNo
      // };
      // console.log(roNo);
      // firstPrintRepairOrder(roNo);
      this.isOrderShow = true;
      this.$nextTick(() => {
        this.$refs.print.EXCUTE_PRINT();
      });
    },

    closeDialog() {
      this.$emit('close', false);
    }
  }
};
</script>

<style lang="less" scoped></style>
